/** ele admin license by http://eleadmin.com */
import NProgress from 'nprogress';
import ElementUI from 'element-ui';
import defaultLang from './lang/zh-CN.js';
// 组件
import EleAvatarList from './ele-avatar-list';
import EleBasicSelect from './ele-basic-select';
import EleDot from './ele-dot';
import EleEmpty from './ele-empty';
import EleProLayout from './ele-pro-layout';
import EleProTable from './ele-pro-table';
import EleResult from './ele-result';
import EleTableDraggable from './ele-table-draggable';
import EleTableSelect from './ele-table-select';
import EleTagsInput from './ele-tags-input';
import EleToolbar from './ele-toolbar';
import { EleToolItem } from './ele-toolbar';
import EleTreeSelect from './ele-tree-select';
// util
import {
  digit,
  toDateString,
  timeAgo,
  toTreeData,
  eachTreeData,
  formatTreeData,
  uuid,
  random,
  formatNumber,
  escape,
  htmlToText,
  deepClone,
  assignObject,
  isUrl,
  bd09ToGcj02,
  gcj02ToBd09,
  play,
  device,
  countdown,
  toggleFullscreen,
  isFullscreen,
  screenWidth,
  screenHeight,
  exportSheet,
  combineArrays
} from './utils/index.js';
// menu util
import { menuToRoutes, formatMenus } from './utils/menu-util.js';
// message loading
import messageLoading from './utils/message-loading.js';

export {
  // 组件
  EleAvatarList,
  EleBasicSelect,
  EleDot,
  EleEmpty,
  EleProLayout,
  EleProTable,
  EleResult,
  EleTableDraggable,
  EleTableSelect,
  EleTagsInput,
  EleToolbar,
  EleToolItem,
  EleTreeSelect,
  // util
  digit,
  toDateString,
  timeAgo,
  toTreeData,
  eachTreeData,
  formatTreeData,
  uuid,
  random,
  formatNumber,
  escape,
  htmlToText,
  deepClone,
  assignObject,
  isUrl,
  bd09ToGcj02,
  gcj02ToBd09,
  play,
  device,
  countdown,
  toggleFullscreen,
  isFullscreen,
  screenWidth,
  screenHeight,
  exportSheet,
  combineArrays,
  // menu util
  menuToRoutes,
  formatMenus,
  // message loading
  messageLoading
};

export default {
  install: function(Vue, opt) {
    // NProgress
    NProgress.configure(
      Object.assign(
        {
          speed: 200,
          minimum: 0.02,
          trickleRate: 0.1,
          trickleSpeed: 200,
          showSpinner: false
        },
        opt?.nProgress
      )
    );

    // ElementUI
    Vue.use(
      ElementUI,
      Object.assign(
        {
          size: 'medium',
          locale: defaultLang
        },
        opt
      )
    );

    // 注册全局组件
    Vue.use(EleAvatarList);
    Vue.use(EleBasicSelect);
    Vue.use(EleDot);
    Vue.use(EleEmpty);
    Vue.use(EleProLayout);
    Vue.use(EleProTable);
    Vue.use(EleResult);
    Vue.use(EleTableDraggable);
    Vue.use(EleTableSelect);
    Vue.use(EleTagsInput);
    Vue.use(EleToolbar);
    Vue.use(EleTreeSelect);

    // 添加全局属性
    Vue.prototype.$ELEADMIN = {
      request: opt?.request,
      response: opt?.response
    };
    Vue.prototype.$messageLoading = messageLoading;
    Vue.prototype.$util = {
      digit,
      toDateString,
      timeAgo,
      toTreeData,
      eachTreeData,
      formatTreeData,
      uuid,
      random,
      formatNumber,
      escape,
      htmlToText,
      deepClone,
      assignObject,
      isUrl,
      bd09ToGcj02,
      gcj02ToBd09,
      play,
      device,
      countdown,
      toggleFullscreen,
      isFullscreen,
      screenWidth,
      screenHeight,
      exportSheet,
      combineArrays
    };

    // 添加全局过滤器
    Vue.filter('escape', (value) => escape(value));
    Vue.filter('htmlToText', (value) => htmlToText(value));
    Vue.filter('digit', (value, length) => digit(value, length));
    Vue.filter('timeAgo', (value, onlyDate) => timeAgo(value, onlyDate));
    Vue.filter('toDateString', (value, format) => toDateString(value, format));
  }
};
